package com.cqut.hfh.ordering.service.Impl;

import com.cqut.hfh.ordering.pojo.FoodPic;
import com.cqut.hfh.ordering.service.IFodPicService;
import com.cqut.hfh.ordering.utils.EntityIdutils;
import com.cqut.li.mybatisutil.dao.base.Dao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author LJH
 * @date 2019/6/26-17:01
 */
@Service
public class FodPicServiceImpl implements IFodPicService {

    @Resource
    private Dao dao;

    @Override
    public void savePic(String bus_id, String pic_site) {
        FoodPic f = new FoodPic();
        f.setPic_site(pic_site);
        f.setBus_id(bus_id);
        f.setOptime(new Date());
        f.setPic_id(EntityIdutils.getId());

        dao.save(f);
    }

    @Override
    public void updatePic(String food_id, String pic_site) {
        FoodPic f = new FoodPic();
        f.setPic_site(pic_site);
//        dao.updatePropByID(f, food_id);
        List<FoodPic> byCondition = dao.getByCondition(" bus_id='" + food_id + "'", FoodPic.class);
        if(byCondition != null && byCondition.size() != 0){
            dao.updatePropByCondition(f, " bus_id='" + food_id + "'");
            return;
        }
        savePic(food_id, pic_site);
    }
}
